package com.jwd.avmanager.test;

import com.jwd.avmanager.util.DebugLogger;

import java.util.ArrayList;

public class testG {
    public static void main(String[] args) {
//        byte[] bytes = {101, 32, 0, 0, 21, 0, 0, 0, -121, 0, 0, 0, 56, 57, 46, -56, -70, -41, -23, 49, 59};
//
//        ArrayList<AuGroupBean> groupChatData = testG.getGroupChatData(bytes);
//        DebugLogger.debug(groupChatData.toString());
//        for (AuGroupBean groupChatDatum : groupChatData) {
//            DebugLogger.debug(groupChatDatum.id);
//            DebugLogger.debug(groupChatDatum.name);
//            DebugLogger.debug(groupChatDatum.onlineValue);
//        }

//        String s = "12313uu";
//        Integer id = null;
//        try {
//            id = Integer.valueOf(s);
//        } catch (NumberFormatException e) {
//            e.printStackTrace();
//            System.err.println("参数异常");
//            return;
//        }
//        DebugLogger.debug(id);

        byte[] bytes = new byte[]{-100, -1};
        byte[] bytes1 = new byte[]{0, 0};
        byte[] bytes2 = new byte[]{-1};
//        DebugLogger.debug(ByteUtil.wholeToInt(bytes));
//        DebugLogger.debug(ByteUtil.wholeToInt(bytes1));
//        DebugLogger.debug(ByteUtil.wholeToInt(bytes2));


    }

    /**
     * 切割集群对讲的组群信息
     *
     * @param bytes 原始数据 格式：  ID,Name|ID,Name。。。
     * @return 群列表
     */
    private static ArrayList<AuGroupBean> getGroupChatData(byte[] bytes) {
        ArrayList<AuGroupBean> auGroupList = new ArrayList<>();
        byte cmd_length[] = new byte[4];
        System.arraycopy(bytes, 4, cmd_length, 0, 4);
        int size = 0;
        String groupName = "";
        try {
            for (int i = cmd_length.length - 1; i >= 0; i--) {
                size <<= 8;
                size |= (cmd_length[i] & 0x000000ff);
            }
            int group_length = size - 12;
            if (group_length <= 0)
                return auGroupList;
            byte b_groupName[] = new byte[group_length];
            System.arraycopy(bytes, 12, b_groupName, 0, group_length);
            groupName = new String(b_groupName, "GB2312").trim();//取出所有群字符串
//            DebugLogger.debug(groupName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String g_parts[] = groupName.split("\\|");//切割出每组群
        for (int j = 0; j < g_parts.length; j++) {
            String s_parts[] = g_parts[j].split(",");
            if (s_parts.length < 2)//错误格式
                continue;

            AuGroupBean auGroupBean = new AuGroupBean(s_parts[0], s_parts[1]);//切割出每组ID和群名称
//            Log.e(TAG, "getGroupChatData: "+auGroupBean.id );
            DebugLogger.info("testG.getGroupChatData   " + auGroupBean.id);
            auGroupList.add(auGroupBean);//加入列表
        }
        return auGroupList;
    }
}
